import { templateApi } from '@/api'
import type { ModelTreeItem, LastNodeItem, LastNodeDataItem } from '@/api/modules/template'
import type { STORAGE_MODES } from '@/enum/modules/indicator'

export function useLoadData() {
  // templateApi.getModelTree('TPF')
  // templateApi.loadAllLastModelTag(90)
  // templateApi.loadAllLastModelData({
  //   modelId: 90,
  //   timeType: STORAGE_MODES.YEAR,
  //   dataTime: '2025',
  // })
  const modelTreeItem = ref<ModelTreeItem>()
  const lastNodes = ref<LastNodeItem[]>([])
  const lastNodeDataItem = ref<LastNodeDataItem>()

  async function getModelTree(modelCode: string) {
    const { data } = await templateApi.getModelTree(modelCode)
    modelTreeItem.value = data
    return data
  }

  async function loadAllLastModelTag(modelId?: number, modelCode?: string) {
    const { data } = await templateApi.loadAllLastModelTag(modelId, modelCode)
    lastNodes.value = data
    return data
  }

  async function loadAllLastModelData(params: {
    modelId?: number
    modelCode?: string
    timeType: STORAGE_MODES
    dataTime: string
  }) {
    const { data } = await templateApi.loadAllLastModelData(params)
    lastNodeDataItem.value = data
    return data
  }
  return {
    modelTreeItem,
    lastNodes,
    lastNodeDataItem,
    getModelTree,
    loadAllLastModelTag,
    loadAllLastModelData,
  }
}
